import turtle
import datetime
 
# 设置画布和画笔
screen = turtle.Screen()
screen.title("数码管显示实验")
screen.setup(width=800, height=600)
pen = turtle.Turtle()
pen.speed(0)  # 设置画笔速度为最快
pen.hideturtle()  # 隐藏画笔
 
# 定义绘制七段数码管的函数
def draw_segment(x, y, length, width, color='black'):
    pen.penup()
    pen.goto(x - length / 2, y)
    pen.pendown()
    pen.setheading(0)  # 朝向东
    pen.forward(length)
    pen.setheading(90)  # 朝向北
    pen.forward(width)
    pen.setheading(180)  # 朝向西
    pen.forward(length)
    pen.setheading(270)  # 朝向南
    pen.forward(width)
    pen.penup()
 
def draw_digit(digit, x, y, size=50):
    segments = [
        (True, False, False, True, True, False, False),  # 0
        (False, True, False, False, False, False, False),  # 1
        (True, True, False, True, False, True, True),  # 2
        (True, True, False, True, False, False, True),  # 3
        (False, True, False, True, True, True, False),  # 4
        (True, False, True, True, False, True, True),  # 5
        (True, False, True, True, True, True, True),  # 6
        (False, False, False, False, False, False, False),  # 7 (not used)
        (True, True, True, True, True, True, True),  # 8
        (True, True, True, True, False, True, True)   # 9
    ]
    
    gap = size // 10
    for i, segment in enumerate(segments[digit]):
        if segment:
            draw_segment(x + i * (size + gap), y, size, size // 5)
 
def draw_date(date, x, y, size=50):
    for i, char in enumerate(date):
        if char.isdigit():
            digit = int(char)
            draw_digit(digit, x + i * (size * 1.2 + 10), y, size)
 
# 获取系统日期
today = datetime.datetime.now().strftime("%Y-%m-%d")
 
# 自定义特殊日期
special_date = "2023-10-01"  # 示例日期，可以修改为实际日期
 
# 计算日期差值
today_date = datetime.datetime.strptime(today, "%Y-%m-%d")
special_date_date = datetime.datetime.strptime(special_date, "%Y-%m-%d")
delta = today_date - special_date_date
days_diff = delta.days
 
# 绘制内容
pen.penup()
pen.goto(-350, 200)
pen.write("今天是，对应的日期是系统时间：", align="left", font=("Arial", 16, "normal"))
pen.goto(-350, 150)
draw_date(today, -300, 150)
 
pen.goto(-350, 100)
pen.write("我加入Python团队的时间（示例）：", align="left", font=("Arial", 16, "normal"))
pen.goto(-350, 50)
draw_date(special_date, -300, 50)
 
pen.goto(-350, 0)
pen.write(f"距离我加入Python团队已经过去了 {days_diff} 天。", align="left", font=("Arial", 16, "normal"))
 
# 在合适的位置放置自己的姓名
pen.goto(-350, -50)
pen.write("姓名：张三", align="left", font=("Arial", 16, "normal"))
 
# 完成绘图
turtle.done()